import QtQuick 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.15

Item {
    id: lightBar
    width: 532
    height: 36
    property color btnColor:"#AAAAAA"
//    Component.completed: {
//        lightTimer.interval = mymodbus.collectTime;
//        lightTimer.running = true;
//    }
//    Component.onDestruction: {
//        lightTimer.running = false
//    }
    RowLayout {
        x: 2
        y: 0
        width: 532
        height: 36
        Button {
            id: hh
            contentItem: Text {
                opacity: 1
                color: "black"
                text: "HH"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 25
            }
            background: Rectangle {
                    id: recHH
                    color: btnColor
//                        if(Number(mymodbus.weight)>=mymodbus.upperUpperLimit)
//                           {
//                               return "red";
//                           }
//                           else
//                           {
//                               return btnColor;
//                           }
                        //btnColor
                }
            Layout.preferredWidth: 100
            Layout.preferredHeight: 30
        }

        Button {
            id: hl
            contentItem: Text {
                opacity: 1
                color: "black"
                text: "HL"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 25
            }
            background: Rectangle {
                id: recHL
                    color:btnColor
//                        if(Number(mymodbus.weight)>=mymodbus.upperLimit &&Number(mymodbus.weight)<mymodbus.upperUpperLimit)
//                          {
//                              return "red";
//                          }
//                          else
//                          {
//                              return btnColor;
//                          }
                        //btnColor
                }
            Layout.preferredWidth: 100
            Layout.preferredHeight: 30
        }

        Button {
            id: ok
            contentItem: Text {
                opacity: 1
                color: "black"
                text: "OK"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 25
            }
            background: Rectangle {
                id: recOK
                    color: btnColor
//                        if(Number(mymodbus.weight)>mymodbus.lowerLimit && Number(mymodbus.weight)<mymodbus.upperLimit)
//                           {
//                               return "green";
//                           }
//                           else
//                           {
//                               return btnColor;
//                           }
                        //btnColor
                }
            Layout.preferredWidth: 100
            Layout.preferredHeight: 30
        }

        Button {
            id: lo
            contentItem: Text {
                opacity: 1
                color: "black"
                text: "LO"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 25
            }
            background: Rectangle {
                id: recLO
                    color: btnColor
//                        if(Number(mymodbus.weight)>mymodbus.lowerLowerLimit &&Number(mymodbus.weight)<=mymodbus.lowerLimit)
//                           {
//                               return "red";
//                           }
//                           else
//                           {
//                               return btnColor;
//                           }
                        //btnColor
                }
            Layout.preferredWidth: 100
            Layout.preferredHeight: 30
        }

        Button {
            id: ll
            contentItem: Text {
                opacity: 1
                color: "black"
                text: "LL"
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: 25
            }
            background: Rectangle {
                id: recLL
                    color: btnColor
//                        if(Number(mymodbus.weight) <=mymodbus.lowerLowerLimit)
//                           {
//                               return "red";
//                           }
//                           else
//                           {
//                               return btnColor;
//                           }
                        //btnColor
                }
            Layout.preferredWidth: 100
            Layout.preferredHeight: 30
        }
    }
    Timer{
        id:lightTimer
        running: true
        repeat: true
        interval: mymodbus.collectTime
        onTriggered: {
            try
            {
                if(Number(mymodbus.weightNew)>=mymodbus.upperUpperLimit)
                                           {
                                               recHH.color="red"
                                           }
                                           else
                                           {
                                               recHH.color=btnColor;
                                           }
                if(Number(mymodbus.weightNew)>=mymodbus.upperLimit &&Number(mymodbus.weightNew)<mymodbus.upperUpperLimit)
                  {
                      recHL.color="red";
                  }
                  else
                  {
                      recHL.color=btnColor;
                  }
                if(Number(mymodbus.weightNew)>mymodbus.lowerLimit && Number(mymodbus.weightNew)<mymodbus.upperLimit)
                                           {
                                               recOK.color= "green";
                                           }
                                           else
                                           {
                                               recOK.color= btnColor;
                                           }
                if(Number(mymodbus.weightNew)>mymodbus.lowerLowerLimit &&Number(mymodbus.weightNew)<=mymodbus.lowerLimit)
                   {
                       recLO.color = "red";
                   }
                   else
                   {
                       recLO.color = btnColor;
                   }
                if(Number(mymodbus.weightNew) <=mymodbus.lowerLowerLimit)
                   {
                       recLL.color = "red";
                   }
                   else
                   {
                       recLL.color = btnColor;
                   }
            }
            catch(error)
            {
            }

        }
    }
}
